package com.example.hello.client.Row;

import com.example.hello.BootstrapRow;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.ComponentConnector;
import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.ui.AbstractComponentConnector;
import com.vaadin.shared.Connector;
import com.vaadin.shared.ui.Connect;

import java.util.Iterator;

@Connect(BootstrapRow.class)
public class BootstrapRowConnector extends AbstractComponentConnector {

    @Override
    protected Widget createWidget() {
        return GWT.create(VBootstrapRow.class);
    }

    @Override
    public VBootstrapRow getWidget() {
        return (VBootstrapRow) super.getWidget();
    }

    @Override
    public BootstrapRowState getState() {
        return (BootstrapRowState) super.getState();
    }

    @Override
    public void onStateChanged(StateChangeEvent stateChangeEvent) {
        super.onStateChanged(stateChangeEvent);

        BootstrapRowState state = getState();

        VBootstrapRow row = getWidget();

        Iterator<Connector> itr = state.getWidgets().iterator();
        while (itr.hasNext()) {
            row.add(((ComponentConnector) itr.next()).getWidget());
        }
    }

}
